#include "timer.h"

static unsigned long time_counter = 0;

unsigned long gettick(void)
{
  return time_counter * 100 / 1193182;
}

static inline
void outb( unsigned short port, unsigned char val )
{
  asm volatile( "outb %0, %1"
                : : "a"(val), "Nd"(port) );
}

static inline
unsigned char inb( unsigned short port )
{
  unsigned char ret;
  asm volatile( "inb %1, %0"
                : "=a"(ret) : "Nd"(port) );
  return ret;
}

void manage_time(void)
{
  time_counter += inb(0x40);
}
void init_timer (void)
{
  unsigned char conf = 0;

  conf |= BINARY_COUNTER;
  conf |= (MODE_2 << 1);
  conf |= SPECIAL_MODE << 4;
  conf |= COUNTER_0 << 6;
  outb (0x43, conf);
}
